<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<style>
	.TDL{
		text-align:right;
		width:120px;
		height:28px;
	}
	.TDC{
		height: 28px;
	}
</style>
<script type="text/javascript">
$(function(){
	//保存按钮初始化的时候不可用
	$('#btnSave').unbind("click");
	$('#btnSave').addClass("l-btn-disabled");
	
	$('#btnCheck').bind('click',noSqlConfigIsValid);	
	$('#nosql_add_domain').combobox({
		url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!getUnUsedDomians.action',
		valueField:'codeValue',
		textField:'codeName',
 	 	editable:false,
 		required:true,
 		onLoadSuccess:function(){
			$('#nosql_add_domain').combobox('unselect',0);
		}	 	
	});			
});

/**
 * 保存nosql配置信息
 */
function save()
{
	if ($('#nosql_add_form').form("validate"))
	{
		$.ajax({
			type:"post",
			url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!noSqlConfigIsValid.action',
			data:$('#nosql_add_form').serialize(),
			dataType:"json",
			beforeSend:function(){
				$.messager.progress({title : '提示',text : '正在保存，请稍候 ....'});
			},
			timeout:10*1000,
			error:function(){
				$.messager.progress('close');
				changeSaveBtnStyle(false);
				$.messager.show({title:'提示',msg:'存储数据源配置不正确，请检查！'});
			},
			success:function(result){
				if(result==true){
					$('#nosql_add_form').form('submit', {   
						url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!savaNoSqlConfig.action',
						success:function(result){
							$.messager.progress('close');
							var data=$.parseJSON(result);
							//显示提示信息
							window.top.$.messager.show({title:'提示',msg:data.returnMsg});
							//调用dialog的关闭方法
							$("#saveDiv").dialog('close');
						}  
					}); 
				}else{
					$.messager.progress('close');
					changeSaveBtnStyle(false);
					$.messager.show({title:'提示',msg:'存储数据源配置不正确，请检查！'});
				}
			}
			
		});
	}
}

/**
 * nosql验证
 */
function noSqlConfigIsValid(){
	if ($('#nosql_add_form').form("validate"))
	{
		$.ajax({
			type:"post",
			url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!noSqlConfigIsValid.action',
			data:$('#nosql_add_form').serialize(),
			dataType:"json",
			beforeSend:function(){
				$.messager.progress({title : '提示',text : '正在验证，请稍候 ....'});
			},
			timeout:10*1000,
			error:function(){
				$.messager.progress('close');
				changeSaveBtnStyle(false);
				$.messager.show({title:'提示',msg:'存储数据源配置不正确，请检查！'});
			},
			complete:function(){
				$.messager.progress('close');
			},
			success:function(result){
				if(result){
					changeSaveBtnStyle(true);
					$.messager.show({title:'提示',msg:'存储数据源配置正确！'});
				}else{
					changeSaveBtnStyle(false);
					$.messager.show({title:'提示',msg:'存储数据源配置不正确，请检查！'});
				}
			}
			
		});
	}
}

/**
 * 根据flag来改变【保存】是否可用
 * @param flag true:【保存】可用  false:【保存】不可用
 */
function changeSaveBtnStyle(flag)
{
	 if (flag == true)
	 {
		 $('#btnSave').removeClass("l-btn-disabled");
		 $('#btnSave').unbind("click");
		 $('#btnSave').bind("click", save);
	 }
	 else
	 {
		 $('#btnSave').addClass("l-btn-disabled");
		 $('#btnSave').unbind("click");
	 }
}

</script>
<form id="nosql_add_form" method="post">
<input type="hidden" id="nosql_add_databaseId" name="databaseId" value="${databaseId}"/>
 		<table border="0" cellpadding="0" cellspacing="0" style="width:100%;" class="table">	   
	    <tr>  	
	      	<td class="TDL"><span style="color:red;font-size:15px">*</span>主机地址：</td>
	      	<td class="TDC"><input type="text" id="nosql_add_hostName" name="hostName" class="easyui-validatebox" data-options="required:true,missingMessage:'主机地址不能为空',validType:'ipValidate'" style="width:150px;"/></td>
	     </tr>
	     <tr>
	     	<td class="TDL"><span style="color:red;font-size:15px">*</span>端口号：</td>
	      	<td class="TDC"><input type="text" id="nosql_add_port" name="port" class="easyui-numberbox" data-options="min:1,required:true,missingMessage:'请输入正确的端口号',validType:'length[1,100]'" style="width:150px;"/></td>
	     </tr>
	     <tr>	
	     	<td class="TDL"><span style="color:red;font-size:15px">*</span>模式名：</td>          
	      	<td class="TDC"><input type="text" id="nosql_add_keySpace" name="keySpace" class="easyui-validatebox" data-options="required:true,missingMessage:'模式名不能为空',validType:['length[1,49]', 'specialCharFilter']" style="width:150px;"/></td>
	     </tr>
	     	
	     <tr>	
	     	<td class="TDL"><span style="color:red;font-size:15px">*</span>域 名：</td>          
	      	<td class="TDC">
	      		<input type="text" id="nosql_add_domain" class="easyui-combobox" name="domain" panelHeight="auto" style="width:150px"/>
	      	</td>
	     </tr>		    
    </table>	
</form> 